var main=angular.module('main');

main.controller('project_managementCtrl', ['$scope', 'http', function($scope, http) {
    http.get('data/projectInfo.json').then(function(data) {
        $scope.projectName = data.projectName;
        $scope.projectDesc = data.projectDesc;
    });
    http.get('data/groupMembers.json').then(function(data) {
        $scope.groupMembers = data;
        $scope.originalMembers = data;
    });
    $scope.newMembers = [];
    $scope.newMember = "";
    $scope.newAuthority = "observer";

    $scope.addMember = function() {
        var member = { 'name': $scope.newMember, 'authority': $scope.newAuthority };
        $scope.groupMembers.push(member);
        $scope.newMembers.push(member);
        $scope.newMember = '';
    };
    $scope.deleteMember = function(member) {
        for (var i = 0; i < $scope.newMembers.length; i++) {
            if ($scope.newMembers[i].name === member.name) {
                $scope.newMembers[i].splice(i, 1);
            }
        }
        var index = $scope.groupMembers.indexOf(member);
        $scope.groupMembers.splice(index, 1);
    };
}]);